ValueFolderTemp='/sps/isc/rneveu/EtudeIRM/Nature/ResultsJournal/';
ValueFolderTemp2='/sps/isc/rneveu/EtudeIRM/Nature/ResultsEditor/';
load([ValueFolderTemp 'ResultsThirdLevelDistributionOutliers.mat']);
VecDistribution=VecResults;
load('/sps/isc/rneveu/EtudeIRM/Nature/EtudeNature.mat');
VecEditors1Temp(1,:)=[];
VecValueEditor=VecEditors1Temp;
load('/sps/isc/rneveu/EtudeIRM/Nature/DonneesNature.mat');
VecValueJournal=VecJournalTemp;
ValueCutoff=1.25;
VecResultsTemp1=[];
VecResultsTemp2=[];
VecResultsTemp11=[];
VecResultsTemp22=[];
VecValueYear=[0 1 2 3 4 5 10];
nMonthMax=12;
n1Temp=0;
VecFigure=[];
for n1=1:323
    ValueTemp=find(VecDistribution(:,1)==n1);
    ValueStartEditor=VecValueEditor{n1,22};
    if size(ValueTemp,1)==1
        if VecDistribution(ValueTemp,2)<=ValueCutoff
            ValueJournal=VecValueEditor{n1,11};
            n3=1;
            TestTemp=0;
            while n3<=size(VecValueJournal,1)&&TestTemp==0
                if strcmpi(ValueJournal,VecValueJournal{n3,1})==1
                    TestTemp=1;
                else
                    n3=n3+1;
                end
            end
            try
            load([ValueFolderTemp2 'FileAnalysisEditor' num2str(n1) '.mat']);
            load([ValueFolderTemp2 'FileAnalysisCharacteristicsEditor' num2str(n1) '.mat']);
            VecValueTemp2=zeros(2,size(VecValueYear,2)*nMonthMax*2);
            VecValueTemp22=[];
            for n2=1:33
                if n2==n3
                    eval(['VecValueTemp=VecResultsEditorAuthors2FilteredJournal' num2str(n2) ';']);
%                     eval(['VecValueTemp=VecResultsEditorAffiliation2Journal' num2str(n2) ';']);
                    VecValueTemp22=VecValueTemp;
                else
                    eval(['VecValueTemp=VecResultsEditorAuthors1FilteredJournal' num2str(n2) ';']);
                    eval(['VecValueTemp=VecResultsEditorAffiliation1Journal' num2str(n2) ';']);
                    if sum(VecValueTemp(2,1:4))>0
                        VecValueTemp2=VecValueTemp2+VecValueTemp;
                    end
                end
            end
            VecValueTemp3=[];
            for n2=1:size(VecValueYear,2)*nMonthMax
                VecValueTemp3=[VecValueTemp3;VecValueTemp2(1,(n2-1)*2+1)-VecValueTemp2(1,(n2-1)*2+2) VecValueTemp2(1,(n2-1)*2+1)/VecValueTemp2(2,(n2-1)*2+1)-(VecValueTemp2(1,(n2-1)*2+2)/VecValueTemp2(2,(n2-1)*2+2))];
%                 VecResultsTemp11=[VecResultsTemp11;VecValueTemp2(1,(n2-1)*2+1) VecValueTemp2(2,(n2-1)*2+1) 1 VecResultsEditor(1,23) VecResultsEditor(1,3) VecResultsEditor(1,16) VecResultsEditor(1,27);VecValueTemp2(1,(n2-1)*2+2) VecValueTemp2(2,(n2-1)*2+2) 2 VecResultsEditor(1,23) VecResultsEditor(1,3) VecResultsEditor(1,16) VecResultsEditor(1,27)];
                VecResultsTemp11=[VecResultsTemp11;VecValueTemp2(1,(n2-1)*2+1) VecValueTemp2(1,(n2-1)*2+2) 1 VecResultsEditor(1,23) VecResultsEditor(1,3) VecResultsEditor(1,16) VecResultsEditor(1,27)];
            end
            VecValueTemp4=[VecResultsEditor(1,23) VecResultsEditor(1,3) VecResultsEditor(1,16) VecResultsEditor(1,27)];
            VecValueTemp3=[VecValueTemp3 repmat(VecValueTemp4,size(VecValueTemp3,1),1) n1*ones(size(VecValueTemp3,1),1)];
            VecResultsTemp1=[VecResultsTemp1;VecValueTemp3];
            VecValueTemp32=[];
            for n2=1:size(VecValueYear,2)*nMonthMax
                VecValueTemp32=[VecValueTemp32;VecValueTemp22(1,(n2-1)*2+1)-VecValueTemp22(1,(n2-1)*2+2) VecValueTemp22(1,(n2-1)*2+1)/VecValueTemp22(2,(n2-1)*2+1)-(VecValueTemp22(1,(n2-1)*2+2)/VecValueTemp22(2,(n2-1)*2+2))];
%                 VecResultsTemp22=[VecResultsTemp22;VecValueTemp22(1,(n2-1)*2+1) VecValueTemp22(2,(n2-1)*2+1) 1 VecResultsEditor(1,23) VecResultsEditor(1,3) VecResultsEditor(1,16) VecResultsEditor(1,27);VecValueTemp22(1,(n2-1)*2+2) VecValueTemp22(2,(n2-1)*2+2) 2 VecResultsEditor(1,23) VecResultsEditor(1,3) VecResultsEditor(1,16) VecResultsEditor(1,27)];
                VecResultsTemp22=[VecResultsTemp22;VecValueTemp22(1,(n2-1)*2+1) VecValueTemp22(1,(n2-1)*2+2) 1 VecResultsEditor(1,23) VecResultsEditor(1,3) VecResultsEditor(1,16) VecResultsEditor(1,27)];
            end
            VecValueTemp32=[VecValueTemp32 repmat(VecValueTemp4,size(VecValueTemp3,1),1) n1*ones(size(VecValueTemp32,1),1)];
            VecResultsTemp2=[VecResultsTemp2;VecValueTemp32];
            n2=2*nMonthMax+8;
            VecFigure=[VecFigure;VecValueTemp2(1,(n2-1)*2+2) VecValueTemp2(1,(n2-1)*2+1) VecValueTemp22(1,(n2-1)*2+2) VecValueTemp22(1,(n2-1)*2+1) VecResultsEditor(1,3) VecResultsEditor(1,27) n1 1];
            VecValueTemp2=zeros(2,size(VecValueYear,2)*nMonthMax*2);
            VecValueTemp22=[];
            for n2=1:33
                eval(['VecValueTemp=VecResultsEditorAffiliation1Journal' num2str(n2) ';']);
                VecValueTemp2=VecValueTemp2+VecValueTemp;
                if n2==n3
                    eval(['VecValueTemp=VecResultsEditorAffiliation2Journal' num2str(n2) ';']);
                    VecValueTemp22=VecValueTemp;
                end
            end
            n2=2*nMonthMax+8;
            VecFigure=[VecFigure;VecValueTemp2(1,(n2-1)*2+2) VecValueTemp2(1,(n2-1)*2+1) VecValueTemp22(1,(n2-1)*2+2) VecValueTemp22(1,(n2-1)*2+1) VecResultsEditor(1,3) VecResultsEditor(1,27) n1 2];
            n1Temp=n1Temp+1;
            end
        end
    end
end

save([ValueFolderTemp2 'FichierFigureCoAuthorsAffiliation.mat'],'VecFigure');

VecResults=[];
VecResults2=[];
VecResults1=[];
VecResults3=[];
for n1=1:size(VecValueYear,2)
    % Case of articles published by co authors in all Nature journals
    VecResultsStartTemp=[];
    VecResultsEndTemp=[];
    for n3=1:n1Temp
        VecResultsStart=[];
        VecResultsEnd=[];
        for n2=8:9
            VecResultsEnd=[VecResultsEnd;VecResultsTemp1((n3-1)*size(VecValueYear,2)*nMonthMax+(n1-1)*nMonthMax+n2,:)];
        end
        for n2=1:7
            VecResultsStart=[VecResultsStart;VecResultsTemp1((n3-1)*size(VecValueYear,2)*nMonthMax+(n1-1)*nMonthMax+n2,:)];
        end
        VecResultsEndTemp=[VecResultsEndTemp;mean(VecResultsEnd,1)];
        VecResultsStartTemp=[VecResultsStartTemp;mean(VecResultsStart,1)];
    end
    VecResultsTemp=VecResultsEndTemp;
%     VecResultsTemp=VecResultsEndTemp-VecResultsStartTemp;
    ValueTemp=find(VecResultsTemp(:,1)<Inf&isnan(VecResultsTemp(:,1))==0);
    ValueTemp2=find(VecResultsTemp(:,2)<Inf&isnan(VecResultsTemp(:,2))==0);
    VecValueResultsTemp=VecResultsTemp;
    [ValueResults1Temp,ValueResults2]=signrank(VecResultsTemp(:,1));
    [ValueResults3Temp,ValueResults4]=signrank(VecResultsTemp(:,2));
    [ValueResults1,ValueResults2]=ttest(VecResultsTemp(ValueTemp,1));
    [ValueResults3,ValueResults4]=ttest(VecResultsTemp(ValueTemp2,2));
    [ValueResultsTemp,stats1]=robustfit(VecResultsTemp(ValueTemp,3),VecResultsTemp(ValueTemp,1));
    [ValueResultsTemp2,stats2]=robustfit(VecResultsTemp(ValueTemp,4),VecResultsTemp(ValueTemp,1));
    [ValueResultsTemp3,stats3]=robustfit(VecResultsTemp(ValueTemp,6),VecResultsTemp(ValueTemp,1));
    [ValueResults2Temp,stats4]=robustfit(VecResultsTemp(ValueTemp2,3),VecResultsTemp(ValueTemp2,2));
    [ValueResults2Temp2,stats5]=robustfit(VecResultsTemp(ValueTemp2,4),VecResultsTemp(ValueTemp2,2));
    [ValueResults2Temp3,stats6]=robustfit(VecResultsTemp(ValueTemp2,6),VecResultsTemp(ValueTemp2,2));
    VecResults=[VecResults;mean(VecResultsTemp(:,1)) sqrt(nanvar(VecResultsTemp(:,1)))/sqrt(size(VecResultsTemp,1)) ValueResults2 ValueResults1Temp mean(VecResultsTemp(ValueTemp2,2)*100) sqrt(nanvar(VecResultsTemp(ValueTemp2,2)*100))/sqrt(size(ValueTemp2,1)) ValueResults4 ValueResults3Temp VecValueYear(1,n1) ValueResultsTemp' stats1.p' NaN ValueResultsTemp2' stats2.p' NaN ValueResultsTemp3' stats3.p' NaN ValueResults2Temp' stats4.p' NaN ValueResults2Temp2' stats5.p' NaN ValueResults2Temp3' stats6.p' NaN size(ValueTemp,1) size(ValueTemp2,1)];
    % Case of articles published by co authors in the editor's journal
    VecResultsStartTemp=[];
    VecResultsEndTemp=[];
    for n3=1:n1Temp
        VecResultsStart=[];
        VecResultsEnd=[];
        for n2=7:9
            VecResultsEnd=[VecResultsEnd;VecResultsTemp2((n3-1)*size(VecValueYear,2)*nMonthMax+(n1-1)*nMonthMax+n2,:)];
        end
        for n2=1:6
            VecResultsStart=[VecResultsStart;VecResultsTemp2((n3-1)*size(VecValueYear,2)*nMonthMax+(n1-1)*nMonthMax+n2,:)];
        end
        VecResultsEndTemp=[VecResultsEndTemp;nanmean(VecResultsEnd,1)];
        VecResultsStartTemp=[VecResultsStartTemp;nanmean(VecResultsStart,1)];
    end
    VecResultsTemp=VecResultsEndTemp;
%     VecResultsTemp=VecResultsEndTemp-VecResultsStartTemp;
    ValueTemp=find(VecResultsTemp(:,1)<Inf&isnan(VecResultsTemp(:,1))==0);
    ValueTemp2=find(VecResultsTemp(:,2)<Inf&isnan(VecResultsTemp(:,2))==0);
    [ValueResults1Temp,ValueResults2]=signrank(VecResultsTemp(:,1));
    [ValueResults3Temp,ValueResults4]=signrank(VecResultsTemp(:,2));
    [ValueResults1,ValueResults2]=ttest(VecResultsTemp(ValueTemp,1));
    [ValueResults3,ValueResults4]=ttest(VecResultsTemp(ValueTemp2,2));
    [ValueResultsTemp,stats]=robustfit(VecResultsTemp(ValueTemp,3),VecResultsTemp(ValueTemp,1));
    [ValueResultsTemp2,stats]=robustfit(VecResultsTemp(ValueTemp,4),VecResultsTemp(ValueTemp,1));
    [ValueResultsTemp3,stats]=robustfit(VecResultsTemp(ValueTemp,6),VecResultsTemp(ValueTemp,1));
    [ValueResults2Temp,stats]=robustfit(VecResultsTemp(ValueTemp2,3),VecResultsTemp(ValueTemp2,2));
    [ValueResults2Temp2,stats]=robustfit(VecResultsTemp(ValueTemp2,4),VecResultsTemp(ValueTemp2,2));
    [ValueResults2Temp3,stats]=robustfit(VecResultsTemp(ValueTemp2,6),VecResultsTemp(ValueTemp2,2));
    VecResults2=[VecResults2;mean(VecResultsTemp(:,1)) sqrt(nanvar(VecResultsTemp(:,1)))/sqrt(size(VecResultsTemp,1)) ValueResults2 ValueResults1Temp mean(VecResultsTemp(ValueTemp2,2)) sqrt(nanvar(VecResultsTemp(ValueTemp2,2)))/sqrt(size(ValueTemp2,1)) ValueResults4 ValueResults3Temp VecValueYear(1,n1) ValueResultsTemp' stats1.p' NaN ValueResultsTemp2' stats2.p' NaN ValueResultsTemp3' stats3.p' NaN ValueResults2Temp' stats4.p' NaN ValueResults2Temp2' stats5.p' NaN ValueResults2Temp3' stats6.p' NaN size(ValueTemp,1) size(ValueTemp2,1)];
    VecValueResultsTemp=VecResultsTemp(:,2)-VecValueResultsTemp(:,2);
    ValueTemp=find(VecValueResultsTemp(:,1)<Inf&isnan(VecValueResultsTemp(:,1))==0);
    [ValueResults1Temp,ValueResults2]=signrank(VecValueResultsTemp(ValueTemp,1));
    [ValueResults1,ValueResults2]=ttest(VecValueResultsTemp(ValueTemp,1));
    VecResults3=[VecResults3;nanmean(VecValueResultsTemp(ValueTemp,1)) sqrt(nanvar(VecValueResultsTemp(ValueTemp,1))) ValueResults1Temp ValueResults2 VecValueYear(1,n1)];
end

